<div class="layui-form seller-alone-form" style="padding: 20px;">
    <div class="progress-tip">
        微信对账中，请稍后，请勿关闭此窗口
    </div>
    <div id="progress-bar">
        <div class="layui-progress layui-progress-big" lay-filter="billing" >
            <div class="layui-progress-bar" lay-percent="0%"></div>
        </div>
    </div>
    
    <div>
        <label class="layui-form-label"></i>同步详情：</label>
        <textarea id="container" name="content" style="width:100%;height:200px;" type="text/plain" required  lay-verify="required" class="layui-textarea"></textarea>
    </div>

    <div>
        <div class="layui-input-block" style = 'margin-top: 10px; margin:10px auto'> 
            <button type="button" id="btnClose" class="layui-btn layui-btn-disabled" style = "display:block; margin:0 auto" lay-submit lay-filter="close">关闭</button>
        </div>
    </div>
</div>
<style>
    .progress-tip{
        padding: 10px;
        text-align: center;
    }
</style>
<script> 
    layui.use('form', function(){
        var form = layui.form;
        form.render();

        var element = layui.element;
        element.render();
        var dates = "{$dates}";
        var values = dates.split(","); 
        
        $("#container").val("开始对账" + '\r\n');
        doBilling(values, 0);
        function doBilling(values, index) {
            $.ajax({
                type: "POST",
                url: "{:url('Report/dobillingds')}",
                data: {
                    "date": values[index],
                    "index": index
                },
                success: function(res) {
                    if(res.status) { 
                        if (res.data.index < values.length) {
                            element.progress('billing', Math.ceil((((res.data.index) * 100)/ values.length)) + '%');
                            $("#container").val($("#container").val() + res.data.date + '\r\n');
                            doBilling(values, res.data.index); 
                        } else {
                            element.progress('billing', '100%');
                            $('#btnClose').removeClass("layui-btn-disabled");
                            $("#container").val($("#container").val() + res.data.date + '\r\n');
                            $("#container").val($("#container").val() + "对账完成" + '\r\n');
                        }
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });　
        }
  
    }); 
</script>